package com.dwxt.community.controller;

import com.dwxt.common.base.*;
import com.dwxt.community.service.*;
import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

/**
 *  资讯
 * @author shenwenkang
 */
@RestController
@RequestMapping("/cms/information")
public class InformationController {

    @Autowired
    private InformationService informationService;

    /**
     * showdoc
     * @catalog 社区后台管理/资讯
     * @title 获取资讯列表
     * @description 获取资讯列表
     * @method get
     * @url /cms/information/get
     * @param pageNum         非必须 Integer 当前页
     * @param pageSize        非必须 Integer 条数
     * @param type            非必须 String 资讯类型
     * @param recommend       非必须 Integer 是否推荐 1：推荐 0不推荐
     * @return {"status":200,"msg":"SUCCESS","data":{"total":7,"list":[{"id":"6","title":"【社区】重庆尚有无症状感染者11例正在接受医学观察其中境外输入4例","cover":"http://125.62.47.82/upload/2.jpg","video":"http://125.62.47.82/upload/xxx.mp4","auther":"dwxt","release":1,"boutique":0,"createTime":"2020-04-0119:20:43","updateTime":"2020-04-1007:43:47","adTypeId":2,"hits":3,"star":0,"releaseTime":"2020-04-0906:23:25","adLocationId":"4","recommend":0,"priority":5,"starIs":false,"adType":{"id":"2","name":"社区","createTime":1585852236000,"updateTime":1585588152000,"description":"社区"}}],"pageNum":1,"pageSize":10,"size":7,"startRow":1,"endRow":7,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1}}
     */
    @GetMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String type,Integer recommend) {
        return informationService.get(pageNum, pageSize, type,recommend);
    }
    /**
     * showdoc
     * @catalog 社区/资讯
     * @title 获取资讯详情
     * @method  get
     * @param id 必须 String 资讯ID
     * @description  获取资讯详情  每调用一次该接口，对应资讯的点击量会加1
     * @url /cms/information/detail
     * @return {"status":200,"msg":"SUCCESS","data":{"id":"158639997475035","title":"个性化是商业的未来","cover":"http://192.168.1.6:9091/upload/20200409103810495.jpg","auther":"baiyuzhong","release":1,"createTime":"2020-04-0810:39:35","updateTime":"2020-04-1310:49:01","adTypeId":1,"hits":2,"star":0,"releaseTime":"2020-04-0810:49:18","adLocationId":"5","recommend":1,"priority":2,"content":"大。","starIs":false,"adType":{"id":"1","name":"广告","createTime":"2020-04-02T18:30:34.000+0000","updateTime":"2020-03-30T17:09:12.000+0000","description":"广告"}}}
     */
    @GetMapping("/detail")
    public BaseResult detail(String id){
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationService.detail(id);
    }
    /**
     * showdoc
     * @catalog 社区/资讯
     * @title 轮播图
     * @method  get
     * @description  轮播图
     * @url /cms/information/viewPaper
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":"10","name":"轮播图1","informationVo":{"id":"4","title":"【城市】渝湘高铁重庆至黔江（武隆段）开建武隆40分钟可到主城","cover":"http://125.62.47.82/upload/2.jpg","auther":"dwxt","hits":4,"star":2,"releaseTime":"2020-04-0914:23:26","starIs":false}}}]}
     */
    @GetMapping("/viewPaper")
    public BaseResult viewPaper(){
        return informationService.selectViewPaper();
    }
    /**
     * showdoc
     * @catalog 社区/资讯
     * @title 广告位
     * @method  get
     * @description  广告位
     * @url /cms/information/adInfo
     * @return
     */
    @GetMapping("/adInfo")
    public BaseResult adInfo(){
        return informationService.selectAdInfo();
    }

    /**
     * showdoc
     * @catalog 社区/资讯
     * @title 点赞
     * @method  post
     * @param id 必须 String 资讯ID
     * @description  点赞
     * @url /cms/information/clickStar
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @PostMapping("/clickStar")
    public BaseResult clickStar(String id){
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationService.clickStar(id);
    }


    @GetMapping("/getRecommend")
    public BaseResult getRecommend(Integer type) {
        if (ObjectUtils.isEmpty(type)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return informationService.getRecommend(type);
    }
}
